package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.mapper.WellProductMapper;
import com.example.entity.WellProduct;
import com.example.service.WellProductService;
import com.example.entity.WellProduct;
import com.example.service.WellProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 生产井(WellProduct)表服务实现类
 *
 * @author makejava
 * @since 2025-09-17 19:41:53
 */
@Service("wellProductService")
public class WellProductServiceImpl extends ServiceImpl<WellProductMapper, WellProduct> implements WellProductService {
    @Autowired
    private WellProductMapper mapper;

    // 获取所有井号
// 获取所有井号
    public List<String> getWellList() {
        return mapper.selectList(null).stream()
                .map(WellProduct::getJh)
                .distinct()
                .toList();
    }


    // 多井号 + 时间范围查询
    public Map<String, List<WellProduct>> getWellData(List<String> jhs, String startDate, String endDate) {
        Map<String, List<WellProduct>> result = new HashMap<>();
        for (String jh : jhs) {
            QueryWrapper<WellProduct> query = new QueryWrapper<>();
            query.eq("jh", jh)
                    .between("date", startDate, endDate)
                    .orderByAsc("date");

            List<WellProduct> data = mapper.selectList(query);
            result.put(jh, data);
        }
        return result;
    }
}

